﻿using System;
using System.Collections.Generic;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Primitives;

namespace ZYing.LiquidThemeEngine.Caching
{
    public class NullMemoryCache : IMemoryCache
    {
        private NullMemoryCache()
        {
        }

        public static NullMemoryCache Instance { get; } = new();

        public ICacheEntry CreateEntry(object key)
        {
            return new NullCacheEntry {Key = key};
        }

        public void Dispose()
        {
        }

        public void Remove(object key)
        {
        }

        public bool TryGetValue(object key, out object value)
        {
            value = default;
            return false;
        }

        private class NullCacheEntry : ICacheEntry
        {
            public object Key { get; set; }
            public object Value { get; set; }
            public DateTimeOffset? AbsoluteExpiration { get; set; }
            public TimeSpan? AbsoluteExpirationRelativeToNow { get; set; }
            public TimeSpan? SlidingExpiration { get; set; }

            public IList<IChangeToken> ExpirationTokens { get; } = new List<IChangeToken>();

            public IList<PostEvictionCallbackRegistration> PostEvictionCallbacks { get; } =
                new List<PostEvictionCallbackRegistration>();

            public CacheItemPriority Priority { get; set; }
            public long? Size { get; set; }

            public void Dispose()
            {
            }
        }
    }
}